package org.jeecg;

import org.geotools.referencing.GeodeticCalculator;
import org.geotools.referencing.crs.DefaultGeographicCRS;

public class GeoUtilDemo {
    public static double getDistance(double longitude1, double latitude1, double longitude2, double latitude2) {
        // 84坐标系构造GeodeticCalculator
        GeodeticCalculator geodeticCalculator = new GeodeticCalculator(DefaultGeographicCRS.WGS84);
        // 起点经纬度
        geodeticCalculator.setStartingGeographicPoint(longitude1, latitude1);
        // 末点经纬度
        geodeticCalculator.setDestinationGeographicPoint(longitude2, latitude2);
        // 计算距离，单位：米
        return geodeticCalculator.getOrthodromicDistance();
    }
    public static void main(String[] args) {
//        double distance = GeoUtilDemo.getDistance(113.805695, 22.678611, 113.826391, 22.716473);
        double distance = GeoUtilDemo.getDistance(114.084563,22.654229, 114.082652,22.655791 );

        System.out.println(distance);
        // 4701.260219872655
    }
}
